package com.njrsrc.android.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.njrsrc.R;
import com.njrsrc.android.bean.HrLetterInfo;
import com.njrsrc.common.utils.Helpers;

public class HrLetterListAdapter extends BaseAdapter {

	private ArrayList<HrLetterInfo> list = new ArrayList<HrLetterInfo>();
	private Context mContext;

	public HrLetterListAdapter(Context mContext) {
		this.mContext = mContext;
	}
	
	public void setData(ArrayList<HrLetterInfo> data) {
        if (data != null) {
            for (HrLetterInfo operateEntry : data) {
            	list.add(operateEntry);
            }
        }
    }

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup arg2) {
		Holder holder = null;
		if (convertView == null) {
			holder = new Holder();
			LayoutInflater inflater = LayoutInflater.from(mContext);
			convertView = inflater.inflate(R.layout.item_list_hrletter, null);
			holder.hrLetterTitleTextView = (TextView) convertView.findViewById(R.id.hrLetterTitle);
			holder.companyTextView = (TextView) convertView.findViewById(R.id.company);
			holder.dateTextView = (TextView) convertView.findViewById(R.id.date);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		
		HrLetterInfo bean = list.get(position);
		if(bean != null)
		{
			convertView.setTag(R.id.hr_letter_id, bean.getHr_letter_id());
			String date = Helpers.getStandardTimeStr(mContext,bean.getSent_at());
			
			holder.hrLetterTitleTextView.setText(bean.getTitle());
			if(bean.getCompany() != null)
			{
				holder.companyTextView.setText(bean.getCompany().getName());
			}
			holder.dateTextView.setText(date);
		}
		return convertView;
	}

	class Holder {
		TextView hrLetterTitleTextView;
		TextView companyTextView;
		TextView dateTextView;
	}
}
